package guda.house.biz.bo.impl;

import guda.grape.autogen.common.page.BizResult;
import guda.house.biz.beans.ImportOwnerInfo;
import guda.house.biz.beans.ImportParkingInfo;
import guda.house.biz.beans.ImportWaterInfo;
import guda.house.biz.bo.ElecFeeBO;
import guda.house.biz.bo.OwnerBO;
import guda.house.biz.bo.WaterFeeBO;
import guda.house.biz.enums.*;
import guda.house.biz.query.*;
import guda.house.biz.util.FloatUtil;
import guda.house.dal.dao.*;
import guda.house.dal.dataobject.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.support.TransactionCallback;
import org.springframework.transaction.support.TransactionCallbackWithoutResult;
import org.springframework.transaction.support.TransactionTemplate;
import org.springframework.util.StringUtils;

import java.util.Calendar;
import java.util.Date;
import java.util.List;

/**
 * Created by well on 16/3/2.
 */
public class OwnerBOImpl implements OwnerBO {

    @Autowired
    private VillageDAO villageDAO;
    @Autowired
    private BuildingDAO buildingDAO;
    @Autowired
    private UnitDAO unitDAO;
    @Autowired
    private SuiteDAO suiteDAO;
    @Autowired
    private OwnerDAO ownerDAO;
    @Autowired
    private SysVarDAO sysVarDAO;
    @Autowired
    private RenderDAO renderDAO;
    @Autowired
    private ContactDAO contactDAO;
    @Autowired
    private OfficeEmployeeDAO officeEmployeeDAO;
    @Autowired
    private TransactionTemplate transactionTemplate;
    @Autowired
    private WaterFeeBO waterFeeBO;
    @Autowired
    private ElecFeeBO elecFeeBO;
    @Autowired
    private BillWaterDAO billWaterDAO;
    @Autowired
    private BillElecDAO billElecDAO;
    @Autowired
    private WaterRuleDAO waterRuleDAO;
    @Autowired
    private ElecRuleDAO elecRuleDAO;
    @Autowired
    private ParkingDAO parkingDAO;


    @Override
    public BizResult initOwner(final List<ImportOwnerInfo> importOwnerInfoList) {
        final BizResult bizResult = new BizResult();
        if (importOwnerInfoList == null) {
            return bizResult;
        }
        transactionTemplate.execute(new TransactionCallbackWithoutResult() {
            @Override
            protected void doInTransactionWithoutResult(TransactionStatus transactionStatus) {
                int ownerCount = 0;

                for (ImportOwnerInfo importOwnerInfo : importOwnerInfoList) {
                    if (importOwnerInfo.getVillageName() == null) {
                        continue;
                    }

                    VillageQuery villageQuery = new VillageQuery();
                    villageQuery.setVillageName(importOwnerInfo.getVillageName());
                    List<VillageDO> villageDOs = villageDAO.selectForPage(villageQuery);
                    Long villageId = null;
                    if (villageDOs.size() == 0) {
                        VillageDO villageDO = new VillageDO();
                        villageDO.setVillageName(importOwnerInfo.getVillageName());
                        villageDO.setGmtDelivery(new Date());
                        villageId = villageDAO.insert(villageDO);
                    } else {
                        villageId = villageDOs.get(0).getVillageId();
                    }

                    SysVarQuery sysVarQuery = new SysVarQuery();
                    sysVarQuery.setVarType(SysVarTypeEnum.building.name());
                    sysVarQuery.setVillageId(villageId);
                    sysVarQuery.setVarValue(importOwnerInfo.getBuildingType());
                    List<SysVarDO> sysVarDOs = sysVarDAO.selectForPage(sysVarQuery);
                    Long buildingTypeId = null;
                    if (sysVarDOs.size() == 0) {
                        SysVarDO sysVarDO = new SysVarDO();
                        sysVarDO.setVarType(SysVarTypeEnum.building.name());
                        sysVarDO.setVarValue(importOwnerInfo.getBuildingType());
                        sysVarDO.setVillageId(villageId);
                        sysVarDO.setVarStatus(BooleanEnum.TRUE.getVal());
                        buildingTypeId = sysVarDAO.insert(sysVarDO);
                    } else {
                        buildingTypeId = sysVarDOs.get(0).getVarId();
                    }


                    BuildingQuery buildingQuery = new BuildingQuery();
                    buildingQuery.setVillageId(villageId);
                    buildingQuery.setBuildingName(importOwnerInfo.getBuildingName());
                    List<BuildingDO> buildingDOs = buildingDAO.selectForPage(buildingQuery);
                    Long buildingId = null;
                    if (buildingDOs.size() == 0) {
                        BuildingDO buildingDO = new BuildingDO();
                        buildingDO.setBuildingName(importOwnerInfo.getBuildingName());
                        //buildingDO.setBuildingTypeId(buildingTypeId);
                        //buildingDO.setBuildingType(importOwnerInfo.getBuildingType());
                        buildingDO.setVillageId(villageId);
                        buildingId = buildingDAO.insert(buildingDO);
                    } else {
                        buildingId = buildingDOs.get(0).getBuildingId();
                    }

                    UnitQuery unitQuery = new UnitQuery();
                    unitQuery.setVillageId(villageId);
                    unitQuery.setBuildingId(buildingId);
                    unitQuery.setUnitName(importOwnerInfo.getUnitName());
                    List<UnitDO> unitDOs = unitDAO.selectForPage(unitQuery);
                    Long unitId = null;
                    if (unitDOs.size() == 0) {
                        UnitDO unitDO = new UnitDO();
                        unitDO.setUnitName(importOwnerInfo.getUnitName());
                        unitDO.setBuildingId(buildingId);
                        unitId = unitDAO.insert(unitDO);
                    } else {
                        unitId = unitDOs.get(0).getUnitId();
                    }
                    SuiteQuery suiteQuery = new SuiteQuery();
                    suiteQuery.setSuiteName(importOwnerInfo.getSuiteName());
                    suiteQuery.setUnitId(unitId);
                    List<SuiteDO> suiteDOs = suiteDAO.select(suiteQuery);
                    Long suiteId = null;
                    if (suiteDOs.size() > 0) {
                        suiteId = suiteDOs.get(0).getSuiteId();
                    } else {

                        SuiteDO suiteDO = new SuiteDO();
                        suiteDO.setBuildingTypeId(buildingTypeId);
                        suiteDO.setSuiteName(importOwnerInfo.getSuiteName());
                        suiteDO.setUnitId(unitId);
                        suiteDO.setSuiteArea(FloatUtil.convert2gram(importOwnerInfo.getSuiteArea()));
                        suiteDO.setCardOwner(importOwnerInfo.getCardOwner());
                        MeterTypeEnum byDesc = MeterTypeEnum.getByDesc(importOwnerInfo.getWaterUseType());
                        if (byDesc == null) {
                            continue;
                        }
                        suiteDO.setTypeWater(byDesc.getDesc());
                        byDesc = MeterTypeEnum.getByDesc(importOwnerInfo.getElecUseType());
                        if (byDesc == null) {
                            continue;
                        }
                        suiteDO.setTypeElectrical(byDesc.getDesc());
                        suiteDO.setCardWater(importOwnerInfo.getWaterCard());
                        suiteDO.setCardElectrical(importOwnerInfo.getElecCard());
                        SuiteUseTypeEnum byDesc1 = SuiteUseTypeEnum.getByDesc(importOwnerInfo.getSuiteUseType());
                        if (byDesc1 == null) {
                            continue;
                        }
                        suiteDO.setUseType(byDesc1.name());
                        suiteDO.setGmtDelivery(importOwnerInfo.getGmtDelivery());
                        suiteDO.setGmtCheckin(importOwnerInfo.getGmtCheckin());
                        suiteDO.setIsCheckin(importOwnerInfo.getIsCheckin());
                        suiteDO.setIsDecoration(importOwnerInfo.getIsDecoration());
                        //办公室
                        sysVarQuery = new SysVarQuery();
                        sysVarQuery.setVarType(SysVarTypeEnum.office.name());
                        sysVarQuery.setVillageId(villageId);
                        sysVarQuery.setVarValue(importOwnerInfo.getOfficeName());
                        sysVarDOs = sysVarDAO.selectForPage(sysVarQuery);
                        Long officeVarId = null;
                        if (sysVarDOs.size() == 0) {
                            SysVarDO sysVarDO = new SysVarDO();
                            sysVarDO.setVarType(SysVarTypeEnum.office.name());
                            sysVarDO.setVarValue(importOwnerInfo.getOfficeName());
                            sysVarDO.setVillageId(villageId);
                            sysVarDO.setVarStatus(BooleanEnum.TRUE.getVal());
                            officeVarId = sysVarDAO.insert(sysVarDO);
                        } else {
                            officeVarId = sysVarDOs.get(0).getVarId();
                        }
                        suiteDO.setOfficeVarId(officeVarId);
                        //职员
                        OfficeEmployeeQuery officeEmployeeQuery = new OfficeEmployeeQuery();
                        officeEmployeeQuery.setVillageId(villageId);
                        officeEmployeeQuery.setVarId(officeVarId);
                        officeEmployeeQuery.setUserName(importOwnerInfo.getEmployeeName());
                        List<OfficeEmployeeDO> officeEmployeeDOs = officeEmployeeDAO.selectForPage(officeEmployeeQuery);
                        Long officeEmployeeId = null;
                        if (officeEmployeeDOs.size() == 0) {
                            OfficeEmployeeDO officeEmployeeDO = new OfficeEmployeeDO();
                            officeEmployeeDO.setUserName(importOwnerInfo.getEmployeeName());
                            officeEmployeeDO.setVillageId(villageId);
                            officeEmployeeDO.setVarId(officeVarId);
                            officeEmployeeDO.setVarName(importOwnerInfo.getOfficeName());
                            officeEmployeeId = officeEmployeeDAO.insert(officeEmployeeDO);
                        } else {
                            officeEmployeeId = officeEmployeeDOs.get(0).getEmployeeId();
                        }
                        suiteDO.setEmployeeId(officeEmployeeId);
                        suiteDO.setSuiteComment(importOwnerInfo.getComment());
                        suiteId = suiteDAO.insert(suiteDO);
                    }
                    ownerCount++;

                    OwnerDO ownerDO = new OwnerDO();
                    ownerDO.setSuiteId(suiteId);
                    ownerDO.setIsEmployee(importOwnerInfo.getIsEmployee());
                    ownerDO.setOwnerStatus(BooleanEnum.TRUE.getVal());
                    ownerDO.setOwnerName(importOwnerInfo.getOwnerName());
                    ownerDO.setPhone(importOwnerInfo.getPhone());
                    ownerDO.setEmail(importOwnerInfo.getEmail());
                    ownerDO.setQq(importOwnerInfo.getQq());
                    ownerDO.setWeixin(importOwnerInfo.getWeixin());
                    ownerDAO.insert(ownerDO);
                    //设置租客
                    if (StringUtils.hasText(importOwnerInfo.getRentName()) || StringUtils.hasText(importOwnerInfo.getRentPhone())) {

                        RenderDO renderDO = new RenderDO();
                        renderDO.setSuiteId(suiteId);
                        renderDO.setRenderName(importOwnerInfo.getRentName());
                        renderDO.setPhone(importOwnerInfo.getRentPhone());
                        renderDO.setOwnerStatus(BooleanEnum.TRUE.getVal());
                        renderDAO.insert(renderDO);

                    }
                    if (StringUtils.hasText(importOwnerInfo.getRentName2()) || StringUtils.hasText(importOwnerInfo.getRentPhone2())) {

                        RenderDO renderDO = new RenderDO();
                        renderDO.setSuiteId(suiteId);
                        renderDO.setRenderName(importOwnerInfo.getRentName2());
                        renderDO.setPhone(importOwnerInfo.getRentPhone2());
                        renderDO.setOwnerStatus(BooleanEnum.TRUE.getVal());
                        renderDAO.insert(renderDO);

                    }

                    //设置紧急联系人
                    if (StringUtils.hasText(importOwnerInfo.getContactName()) || StringUtils.hasText(importOwnerInfo.getContactPhone())) {

                        ContactDO contactDO = new ContactDO();
                        contactDO.setSuiteId(suiteId);
                        contactDO.setUserName(importOwnerInfo.getContactName());
                        contactDO.setPhone(importOwnerInfo.getContactPhone());
                        contactDO.setOwnerStatus(BooleanEnum.TRUE.getVal());
                        contactDO.setRelation(importOwnerInfo.getContactRelation());
                        contactDAO.insert(contactDO);

                    }
                    if (StringUtils.hasText(importOwnerInfo.getContactName2()) || StringUtils.hasText(importOwnerInfo.getContactPhone2())) {

                        ContactDO contactDO = new ContactDO();
                        contactDO.setSuiteId(suiteId);
                        contactDO.setUserName(importOwnerInfo.getContactName2());
                        contactDO.setPhone(importOwnerInfo.getContactPhone2());
                        contactDO.setOwnerStatus(BooleanEnum.TRUE.getVal());
                        contactDO.setRelation(importOwnerInfo.getContactRelation2());
                        contactDAO.insert(contactDO);

                    }
                }
                bizResult.data.put("ownerCount", ownerCount);
            }
        });

        bizResult.success = true;
        return bizResult;


    }

    @Override
    public BizResult initWater(final List<ImportWaterInfo> importWaterInfoList) {
        final BizResult bizResult = new BizResult();
        if (importWaterInfoList == null) {
            return bizResult;
        }
        transactionTemplate.execute(new TransactionCallbackWithoutResult() {
            @Override
            protected void doInTransactionWithoutResult(TransactionStatus transactionStatus) {
                int ownerCount = 0;

                for (ImportWaterInfo importWaterInfo : importWaterInfoList) {
                    if (importWaterInfo.getVillageName() == null) {
                        throw new RuntimeException("");
                    }

                    VillageQuery villageQuery = new VillageQuery();
                    villageQuery.setVillageName(importWaterInfo.getVillageName());
                    List<VillageDO> villageDOs = villageDAO.selectForPage(villageQuery);
                    Long villageId = null;
                    if (villageDOs.size() == 0) {
                        throw new RuntimeException("");
                    } else {
                        villageId = villageDOs.get(0).getVillageId();
                    }


                    BuildingQuery buildingQuery = new BuildingQuery();
                    buildingQuery.setVillageId(villageId);
                    buildingQuery.setBuildingName(importWaterInfo.getBuildingName());
                    List<BuildingDO> buildingDOs = buildingDAO.selectForPage(buildingQuery);
                    Long buildingId = null;
                    if (buildingDOs.size() == 0) {
                        throw new RuntimeException("");
                    } else {
                        buildingId = buildingDOs.get(0).getBuildingId();
                    }

                    UnitQuery unitQuery = new UnitQuery();
                    unitQuery.setVillageId(villageId);
                    unitQuery.setBuildingId(buildingId);
                    unitQuery.setUnitName(importWaterInfo.getUnitName());
                    List<UnitDO> unitDOs = unitDAO.selectForPage(unitQuery);
                    Long unitId = null;
                    if (unitDOs.size() == 0) {
                        throw new RuntimeException("");
                    } else {
                        unitId = unitDOs.get(0).getUnitId();
                    }
                    SuiteQuery suiteQuery = new SuiteQuery();
                    suiteQuery.setSuiteName(importWaterInfo.getSuiteName());
                    suiteQuery.setUnitId(unitId);
                    List<SuiteDO> suiteDOs = suiteDAO.select(suiteQuery);
                    Long suiteId = null;
                    SuiteDO suiteDO = null;
                    if (suiteDOs.size() == 0) {
                        throw new RuntimeException("");
                    } else {
                        suiteDO = suiteDOs.get(0);
                        suiteId = suiteDOs.get(0).getSuiteId();
                    }


                    if (importWaterInfo.getType().startsWith("水")) {

                        //BuildingDO buildingById = buildingDAO.getBuildingById(buildingId);
                        WaterRuleQuery waterRuleQuery = new WaterRuleQuery();
                        waterRuleQuery.setVillageId(villageId);
                        waterRuleQuery.setBuildingTypeId(suiteDO.getBuildingTypeId());
                        List<WaterRuleDO> waterRuleDOs = waterRuleDAO.selectForView(waterRuleQuery);
                        if (waterRuleDOs.size() == 0) {
                            throw new RuntimeException("小区ID" + villageId + "没有设置电费规则。。");
                        }


                        BillWaterDO billWaterDO = new BillWaterDO();
                        billWaterDO.setSuiteId(suiteId);
                        billWaterDO.setRecordCurrent(importWaterInfo.getRecordCurrent());
                        billWaterDO.setRecordLast(importWaterInfo.getRecordLast());
                        billWaterDO.setDiscount(0L);
                        billWaterDO.setDiscountEstate(0L);
                        billWaterDO.setDiscountSelf(0L);
                        billWaterDO.setGmtRecord(new Date());
                        billWaterDO.setGmtStart(importWaterInfo.getStart());
                        billWaterDO.setGmtEnd(importWaterInfo.getEnd());
                        Calendar calendar = Calendar.getInstance();
                        calendar.setTime(importWaterInfo.getStart());
                        int year = calendar.get(Calendar.YEAR);
                        int month = calendar.get(Calendar.MONTH) + 1;
                        billWaterDO.setRecordYear(year);
                        billWaterDO.setRecordMonth(month);
                        long l = waterFeeBO.countWaterFee(villageId, suiteId, importWaterInfo.getRecordCurrent() - importWaterInfo.getRecordLast());
                        billWaterDO.setPayTotal(l);
                        billWaterDAO.insert(billWaterDO);

                    } else {
                        //BuildingDO buildingById = buildingDAO.getBuildingById(buildingId);

                        ElecRuleQuery elecRuleQuery = new ElecRuleQuery();
                        elecRuleQuery.setVillageId(villageId);
                        elecRuleQuery.setBuildingTypeId(suiteDO.getBuildingTypeId());
                        List<ElecRuleDO> elecRuleDOs = elecRuleDAO.selectForView(elecRuleQuery);
                        if (elecRuleDOs.size() == 0) {
                            throw new RuntimeException("小区ID" + villageId + "没有设置电费规则。。");
                        }

                        BillElecDO billElecDO = new BillElecDO();
                        billElecDO.setSuiteId(suiteId);
                        billElecDO.setRecordCurrent(importWaterInfo.getRecordCurrent());
                        billElecDO.setRecordLast(importWaterInfo.getRecordLast());
                        billElecDO.setDiscount(0L);
                        billElecDO.setDiscountEstate(0L);
                        billElecDO.setDiscountSelf(0L);
                        billElecDO.setGmtRecord(new Date());
                        billElecDO.setGmtStart(importWaterInfo.getStart());
                        billElecDO.setGmtEnd(importWaterInfo.getEnd());
                        Calendar calendar = Calendar.getInstance();
                        calendar.setTime(importWaterInfo.getStart());
                        int year = calendar.get(Calendar.YEAR);
                        int month = calendar.get(Calendar.MONTH) + 1;
                        billElecDO.setRecordYear(year);
                        billElecDO.setRecordMonth(month);
                        long l = elecFeeBO.countElecFee(villageId, suiteId, importWaterInfo.getRecordCurrent() - importWaterInfo.getRecordLast());
                        billElecDO.setPayTotal(l);
                        billElecDAO.insert(billElecDO);
                    }


                }
                bizResult.data.put("ownerCount", ownerCount);
            }
        });

        bizResult.success = true;
        return bizResult;
    }

    @Override
    public BizResult initParking(final List<ImportParkingInfo> importParkingInfoList) {
        final BizResult bizResult = new BizResult();
        if (importParkingInfoList == null) {
            return bizResult;
        }
        transactionTemplate.execute(new TransactionCallbackWithoutResult() {
            @Override
            protected void doInTransactionWithoutResult(TransactionStatus transactionStatus) {
                int ownerCount = 0;

                for (ImportParkingInfo importParkingInfo : importParkingInfoList) {
                    if (importParkingInfo.getVillageName() == null) {
                        throw new RuntimeException("");
                    }

                    VillageQuery villageQuery = new VillageQuery();
                    villageQuery.setVillageName(importParkingInfo.getVillageName());
                    List<VillageDO> villageDOs = villageDAO.selectForPage(villageQuery);
                    Long villageId = null;
                    if (villageDOs.size() == 0) {
                        throw new RuntimeException("");
                    } else {
                        villageId = villageDOs.get(0).getVillageId();
                    }


                    BuildingQuery buildingQuery = new BuildingQuery();
                    buildingQuery.setVillageId(villageId);
                    buildingQuery.setBuildingName(importParkingInfo.getBuildingName());
                    List<BuildingDO> buildingDOs = buildingDAO.selectForPage(buildingQuery);
                    Long buildingId = null;
                    if (buildingDOs.size() == 0) {
                        throw new RuntimeException("");
                    } else {
                        buildingId = buildingDOs.get(0).getBuildingId();
                    }

                    UnitQuery unitQuery = new UnitQuery();
                    unitQuery.setVillageId(villageId);
                    unitQuery.setBuildingId(buildingId);
                    unitQuery.setUnitName(importParkingInfo.getUnitName());
                    List<UnitDO> unitDOs = unitDAO.selectForPage(unitQuery);
                    Long unitId = null;
                    if (unitDOs.size() == 0) {
                        throw new RuntimeException("");
                    } else {
                        unitId = unitDOs.get(0).getUnitId();
                    }
                    SuiteQuery suiteQuery = new SuiteQuery();
                    suiteQuery.setSuiteName(importParkingInfo.getSuiteName());
                    suiteQuery.setUnitId(unitId);
                    List<SuiteDO> suiteDOs = suiteDAO.select(suiteQuery);
                    Long suiteId = null;
                    SuiteDO suiteDO = null;
                    if (suiteDOs.size() == 0) {
                        throw new RuntimeException("");
                    } else {
                        suiteDO = suiteDOs.get(0);
                        suiteId = suiteDOs.get(0).getSuiteId();
                    }

                    int buyed = 1;
                    if (importParkingInfo.getBuyed().equals(OwnerTypeEnum.rent.getDesc())) {
                        buyed = 0;
                    } else if (importParkingInfo.getBuyed().equals(OwnerTypeEnum.owner.getDesc())) {

                    } else {
                        throw new RuntimeException("使用类型字段不正确。。");
                    }
                    String ownerType = null;
                    if (importParkingInfo.getOwnerType().equals("业主")) {
                        ownerType = OwnerTypeEnum.owner.name();
                    } else if (importParkingInfo.getOwnerType().equals("租客")) {
                        ownerType = OwnerTypeEnum.rent.name();
                    } else {
                        throw new RuntimeException("使用者字段不正确。。");
                    }
                    Long ownerId = null;
                    if (StringUtils.hasText(importParkingInfo.getOwnerName())) {
                        if (importParkingInfo.getOwnerType().equals("业主")) {
                            OwnerQuery ownerQuery = new OwnerQuery();
                            ownerQuery.setOwnerName(importParkingInfo.getOwnerName());
                            ownerQuery.setSuiteId(suiteId);
                            List<OwnerDO> ownerDOs = ownerDAO.selectForPage(ownerQuery);
                            if (ownerDOs.size() > 0) {
                                ownerId = ownerDOs.get(0).getOwnerId();
                            }
                        } else {
                            RenderQuery renderQuery = new RenderQuery();
                            renderQuery.setRenderName(importParkingInfo.getOwnerName());
                            renderQuery.setSuiteId(suiteId);
                            List<RenderDO> renderDOs = renderDAO.selectForPage(renderQuery);
                            if (renderDOs.size() > 0) {
                                ownerId = renderDOs.get(0).getRenderId();
                            }
                        }
                    }

                    SysVarQuery sysVarQuery = new SysVarQuery();
                    sysVarQuery.setVarType(SysVarTypeEnum.parking_rent.name());
                    sysVarQuery.setVillageId(villageId);
                    sysVarQuery.setVarValue(importParkingInfo.getParkingType());
                    List<SysVarDO> sysVarDOs = sysVarDAO.selectForPage(sysVarQuery);
                    long parkingTypeId = 0;
                    if (sysVarDOs.size() == 0) {
                        SysVarDO sysVarDO = new SysVarDO();
                        sysVarDO.setVarType(SysVarTypeEnum.parking_rent.name());
                        sysVarDO.setVarValue(importParkingInfo.getParkingType());
                        sysVarDO.setVillageId(villageId);
                        sysVarDO.setVarStatus(BooleanEnum.TRUE.getVal());
                        parkingTypeId = sysVarDAO.insert(sysVarDO);
                    } else {
                        parkingTypeId = sysVarDOs.get(0).getVarId();
                    }


                    //BuildingDO buildingById = buildingDAO.getBuildingById(buildingId);
                    WaterRuleQuery waterRuleQuery = new WaterRuleQuery();
                    waterRuleQuery.setVillageId(villageId);
                    waterRuleQuery.setBuildingTypeId(suiteDO.getBuildingTypeId());
                    List<WaterRuleDO> waterRuleDOs = waterRuleDAO.selectForView(waterRuleQuery);
                    if (waterRuleDOs.size() == 0) {
                        throw new RuntimeException("小区ID" + villageId + "没有设置电费规则。。");
                    }


                    ParkingDO parkingDO = new ParkingDO();
                    parkingDO.setParkingCard(importParkingInfo.getParkingCard());
                    parkingDO.setVillageId(villageId);
                    parkingDO.setParkingTypeId(parkingTypeId);
                    parkingDO.setParkingName(importParkingInfo.getParkingName());
                    parkingDO.setCarNo(importParkingInfo.getCarNo());

                    parkingDO.setOwnerType(ownerType);
                    parkingDO.setOwnerId(ownerId);
                    parkingDO.setBuyed(buyed);
                    parkingDO.setSuiteId(suiteId);
                    parkingDAO.insert(parkingDO);

                    ownerCount++;


                }
                bizResult.data.put("ownerCount", ownerCount);
            }
        });

        bizResult.success = true;
        return bizResult;
    }
}
